all:liblrc.so

ifeq ($(bug),nobug)
debug=
DEBUG=
else
debug=lmp-debug.o
DEBUG= -D__debug__
endif

ifneq ($(ver),)
LRC_VERSION=$(ver)
else
LRC_VERSION=$(shell date +%Y_%m_%d)
endif


CFLAGS=-DHAVE_CONFIG_H -I. -I../../.. -D_REENTRANT -DDBUS_API_SUBJECT_TO_CHANGE -DGNOMELOCALEDIR=\"/usr/local/share/locale\"  -I../../../src/backend -I../../../plparse -pthread -DORBIT2=1 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/freetype2 -I/usr/include/libpng12 -I/usr/include/pixman-1 -I/usr/include/gnome-vfs-2.0 -I/usr/lib/gnome-vfs-2.0/include -I/usr/include/gconf/2 -I/usr/include/orbit-2.0 -I/usr/include/gnome-vfs-module-2.0 -I/usr/include/totem-pl-parser/1/plparser -I/usr/include/libxml2 -I/usr/include/evolution-data-server-2.22 -I/usr/include/libbonobo-2.0 -I/usr/include/bonobo-activation-2.0 -I/usr/include/gstreamer-0.10 -Wall -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wno-sign-compare -I../../../ -I../../../lib -I../../../src -I../../../src/plugins -I./ -Wall -Wchar-subscripts -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wcast-align -Wsign-compare -fno-strict-aliasing -g -Wall $(DEBUG) -DLRC_VERSION=\"$(LRC_VERSION)\"


plugindir=/usr/lib/totem/plugins

OBJ=totem-lrc.o $(debug) http_fetcher.o http_error_codes.o\
  tt-codefunc.o totem-lrc-down.o totem-lrc-func.o totem-lrc-pad.o\
  totem-lrc-win.o


liblrc.so:$(OBJ)
	$(CC) -shared $^ -pthread -Wl,-soname -Wl,$@ -o $@  -lgtk-x11-2.0  -lglib-2.0 -lglade-2.0 -lgthread-2.0

totem-lrc.o:totem-lrc.c totem-lrc.h
	$(CC) $(CFLAGS) -c $< -Dplugindir=\"$(plugindir)\"

lrcshow.o:lrcshow.c totem-lrc.h
	$(CC) $(CFLAGS) -c $< -I/usr/include/libglade-2.0 -D_GNU_SOURCE 

http_fetcher.o:http_fetcher.c 
	$(CC) $(CFLAGS) -c $<

http_error_codes.o:http_error_codes.c
	$(CC) $(CFLAGS) -c $<

totem-lrc-down.o:totem-lrc-down.c totem-lrc-down.h
	$(CC) $(CFLAGS) -c $< -I/usr/include/libglade-2.0 -D_GNU_SOURCE 

totem-lrc-func.o:totem-lrc-func.c totem-lrc-func.h
	$(CC) $(CFLAGS) -c $< -I/usr/include/libglade-2.0 -D_GNU_SOURCE 

totem-lrc-pad.o:totem-lrc-pad.c totem-lrc-pad.h
	$(CC) $(CFLAGS) -c $< -I/usr/include/libglade-2.0 -D_GNU_SOURCE 

totem-lrc-win.o:totem-lrc-win.c
	$(CC) $(CFLAGS) -c $< -I/usr/include/libglade-2.0 -D_GNU_SOURCE 

tt-codefunc.o:tt-codefunc.c
	$(CC) $(CFLAGS) -c $<


ifneq ($(bug),nobug)
lmp-debug.o:lmp-debug.c
	$(CC) $(CFLAGS) -c $<
endif

install:liblrc.so
	@[ -d $(DESTDIR)/$(plugindir)/lrc/ ]||mkdir -m 755 -p $(DESTDIR)/$(plugindir)/lrc/
	install -m 755 $< $(DESTDIR)/$(plugindir)/lrc/
	install -m 755 lrc.totem-plugin.in $(DESTDIR)/$(plugindir)/lrc/lrc.totem-plugin
	install -m 755 down.glade $(DESTDIR)/$(plugindir)/lrc

clean:
	rm -rf *.o *.so *~ ?*/?*/*~ *.deb *.bin *.orig debian/usr

uninstall:
	rm -rf $(DESTDIR)/$(plugindir)/lrc/

deb:
	make clean
	make DESTDIR=$(shell pwd)/debian install
	sed  -i 's/Version:.*/Version: $(LRC_VERSION)/' debian/DEBIAN/control
	dpkg-deb -b debian lrcshow_$(LRC_VERSION)_i386.deb

lrcshow_$(LRC_VERSION)_install.bin:liblrc.so lrcshowbin_h
	@make DESTDIR=./bindir plugindir=. install
	@tar jcpf lrcshow.tar.bz2 -C ./bindir .
	@cat lrcshowbin_h lrcshow.tar.bz2 >$@
	chmod +x $@
	@rm -rf ./bindir lrcshow.*.bz2

bin:lrcshow_$(LRC_VERSION)_install.bin

bin-install:lrcshow_$(LRC_VERSION)_install.bin
	@[ -x $< ]&& $< $(plugindir)

tar:clean
	tar jcpf ../lrcshow-$(LRC_VERSION).tar.bz2 -C .. ./lrc

diff:clean
	/bin/bash -c "cd .. ;diff -uNr $(old) $(new) >diff.patch ;exit 0"

patch:diff
	/bin/sh -c "cd ../$(old);patch -p1 <../diff.patch"

